package userRpc

import (
	"common/discovery"
	"common/logs"
	"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
	"go.opentelemetry.io/otel"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"google.golang.org/grpc/resolver"
	"http-gateway/config"
	"log"
	"pb/user"
)

var LoginServiceClient user.LoginServiceClient

func InitRpcUserClient() {
	etcdRegister := discovery.NewResolver(config.C.EtcdConfig.Addrs, logs.LG)
	resolver.Register(etcdRegister)
	conn, err := grpc.Dial(
		"etcd:///user/1.0.0",
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithStatsHandler(
			otelgrpc.NewClientHandler(
				// 传入你的 TracerProvider
				otelgrpc.WithTracerProvider(otel.GetTracerProvider()),
				// 其他可选配置，如 otelgrpc.WithPropagators(...)
			),
		),
	)
	//conn, err := grpc.Dial("172.28.217.156:8881", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	LoginServiceClient = user.NewLoginServiceClient(conn)
}
